<template>
<h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="user.name">
  <input type="text" placeholder="请输入员工工资" v-model="user.salary">
  <input type="text" placeholder="请输入员工工作" v-model="user.job">
  <button @click="add">添加员工</button>
  <hr>
  <table>
  <tr>
    <th>序号</th>
    <th>名字</th>
    <th>工资</th>
    <th>岗位</th>
  </tr>
  <tr v-for="(u,index) in users">
    <td>{{index+1}}</td>
    <td>{{u.name}}</td>
    <td>{{u.salary}}</td>
    <td>{{u.job}}</td>
  </tr>
  </table>
</template>
<script setup>
import {ref} from "vue";

const user=ref({
  name:'',
  salary:'',
  job:''
})
const users=ref([]);
const add=()=>{
  if(user.value.name.trim()==''||
      user.value.salary.trim()==''||
      user.value.job.trim()==''){
    alert("请输入员工信息");
    return;
  }
  users.value.push(user.value);
  user.value={name:'',salary:'',job:''};
  console.log(users.value);
}
</script>


<style scoped>

</style>